15–212: Principles of Programming Some Notes on Grammars and Parsing

نویسنده

  • Michael Erdmann
چکیده

These notes are intended as a “rough and ready” guide to grammars and parsing. The theoretical foundations required for a thorough treatment of the subject are developed in the Formal Languages, Automata, and Computability course. The construction of parsers for programming languages using more advanced techniques than are discussed here is considered in detail in the Compiler Construction course. Parsing is the determination of the structure of a sentence according to the rules of grammar. In elementary school we learn the parts of speech and learn to analyze sentences into constituent parts such as subject, predicate, direct object, and so forth. Of course it is difficult to say precisely what are the rules of grammar for English (or other human languages), but we nevertheless find this kind of grammatical analysis useful. In an effort to give substance to the informal idea of grammar and, more importantly, to give a plausible explanation of how people learn languages, Noam Chomsky introduced the notion of a formal grammar. Chomsky considered several different forms of grammars with different expressive power. Roughly speaking, a grammar consists of a series of rules for forming sentence fragments that, when used in combination, determine the set of well-formed (grammatical) sentences. We will be concerned here only with one, particularly useful form of grammar, called a context-free grammar. The idea of a context-free grammar is that the rules are specified to hold independently of the context in which they are applied. This clearly limits the expressive power of the formalism, but is nevertheless powerful enough to be useful, especially with computer languages. To illustrate the limitations of the formalism, Chomsky gave the now-famous sentence “Colorless green ideas sleep furiously.” This sentence is grammatical according to some (fairly obvious) context-free rules: it has a subject and a predicate, with the subject modified by two adjectives and the predicate by an adverb. It is debatable whether it is “really” grammatical, precisely because we’re uncertain exactly what is the boundary between that which is grammatical and that which is meaningful. We will dodge these questions by avoiding consideration of interpreted languages (those with meaning), and instead focus on the mathematical notion of a formal language, which is just a set of strings over a specified alphabet. A formal language has no intended meaning, so we avoid questions like those suggested by Chomsky’s example.1 ∗Modified from a draft by Robert Harper, 1997. He has given many others. For example, the two sentences “Fruit flies like a banana.” and “Time flies like an

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

15–212: Fundamental Structures of Computer Science II Some Notes on Grammars and Parsing

These notes are intended as a “rough and ready” guide to grammars and parsing. The theoretical foundations required for a thorough treatment of the subject are developed in the Formal Languages, Automata, and Computability course. The construction of parsers for programming languages using more advanced techniques than are discussed here is considered in detail in the Compiler Construction course.

متن کامل

Scannerless Boolean Parsing

Scannerless generalized parsing techniques allow parsers to be derived directly from unified, declarative specifications. Unfortunately, in order to uniquely parse existing programming languages at the character level, disambiguation extensions beyond the usual context-free formalism are required. This paper explains how scannerless parsers for boolean grammars (context-free grammars extended w...

متن کامل

A Case Study in Functional Programming: Generating Eecient Functional Lr(1) Parsers

This paper presents a case study in functional programming. The paper is based upon a chapter of the course notes of a grammars and parsing course which the authors have given to undergraduate students. The chapter presents a functional program that generates eecient functional LR(1) parsers.

متن کامل

From Contextual Grammars to Range Concatenation Grammars

Though the field of natural language processing is one of the major aims that has led to the definition of contextual grammars, very little was made on that subject. One reason is certainly the lack of efficient parsers for contextual languages. In this paper we show how some subclasses of contextual grammars can be translated into equivalent range concatenation grammars and can thus be parsed ...

متن کامل

Context-Free Grammars: Covers, Normal Forms, and Parsing

Let's read! We will often find out this sentence everywhere. When still being a kid, mom used to order us to always read, so did the teacher. Some books are fully read in a week and we need the obligation to support reading. What about now? Do you still love reading? Is reading only for you who have obligation? Absolutely not! We here offer you a new book enPDFd context free grammars covers nor...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2010